//
//  KATTableBuilder.m
//  KATFramework
//
//  Created by Kantice on 15/9/9.
//  Copyright (c) 2015年 KatApp. All rights reserved.
//

#import "KATTableBuilder.h"

@implementation KATTableBuilder

+ (instancetype)builderWithTable:(KATTableView *)table andStyle:(int)style andCellHeight:(float)cellHeight
{
    KATTableBuilder *builder=[[[self alloc] init] autorelease];
    
    builder.table=table;//绑定table
    builder.table.builder=builder;//互相绑定
    builder.screenSize=[[UIScreen mainScreen] bounds].size;
    
    //配置样式
    switch(style)
    {
        case TABLE_STYLE_NONE:
            
            break;
            
            
        case TABLE_STYLE_BASIC://基本类型
            
            //高度
            if(cellHeight<1.0)
            {
                builder.table.cellHeight=(builder.screenSize.width-320.0)*0.1+320*0.2;
            }
            else
            {
                builder.table.cellHeight=cellHeight;
            }
            
            //图层颜色
            builder.table.midBgColor=KCOLOR_BACKGROUND;
            
            //分割线
            builder.table.hasLine1=YES;
            builder.table.line1Frame=CGRectMake(-builder.table.cellWidth, builder.table.cellHeight-0.5, builder.table.cellWidth*3, 0.5);
            builder.table.line1Color=KCOLOR_LINE;
            
            //图片
            builder.table.hasImage=YES;
            builder.table.isRemoteImage=YES;
            builder.table.imageFrame=CGRectMake(builder.table.cellHeight*0.2, builder.table.cellHeight*0.1, builder.table.cellHeight*0.8, builder.table.cellHeight*0.8);
            
            //标题
            builder.table.hasTitle=YES;
            builder.table.titleFrame=CGRectMake(builder.table.cellHeight*1.2, builder.table.cellHeight*0.1, builder.table.cellWidth-builder.table.cellHeight*1.4-builder.table.cellHeight*0.44, builder.table.cellHeight*0.45);
            builder.table.titleFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.22];
            builder.table.titleAlignment=NSTextAlignmentLeft;
            builder.table.titleLineBreak=NSLineBreakByTruncatingTail;
            builder.table.titleLines=1;
            builder.table.titleColor=KCOLOR_DARK;
            
            //内容
            builder.table.hasContent=YES;
            builder.table.contentFrame=CGRectMake(builder.table.cellHeight*1.2, builder.table.cellHeight*0.55, builder.table.cellWidth-builder.table.cellHeight*1.4, builder.table.cellHeight*0.35);
            builder.table.contentFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.18];
            builder.table.contentAlignment=NSTextAlignmentLeft;
            builder.table.contentLineBreak=NSLineBreakByTruncatingTail;
            builder.table.contentLines=1;
            builder.table.contentColor=KCOLOR_GRAY;
            
            //徽标
            builder.table.hasBadge=YES;
            builder.table.badgeFrame=CGRectMake(builder.table.cellWidth-builder.table.cellHeight*0.32-builder.table.cellHeight*0.2, builder.table.cellHeight*0.16, builder.table.cellHeight*0.40, builder.table.cellHeight*0.20);
            builder.table.badgeFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.14];
            builder.table.badgeTextColor=[UIColor whiteColor];
            builder.table.badgeBgColor=KCOLOR_RED;
            builder.table.badgeCorner=0.25;
            
            //点击颜色
            builder.table.tapedBgColor=KCOLOR_CYAN;
            builder.table.tapedButtonColor=COLOR(COLOR_SMOKE);
            builder.table.tapedTextColor=COLOR(COLOR_SMOKE);
            
            //点击变色
            builder.table.isTapToChangeFaceLayerColor=YES;
            
            break;
            
            
        case TABLE_STYLE_MESSAGE://信息类型
            
            //高度
            if(cellHeight<1.0)
            {
                builder.table.cellHeight=(builder.screenSize.width-320.0)*0.1+320*0.18;
            }
            else
            {
                builder.table.cellHeight=cellHeight;
            }
            
            //图层颜色
            builder.table.midBgColor=KCOLOR_BACKGROUND;
            
            //分割线
            builder.table.hasBottomLine=YES;
            builder.table.bottomLineFrame=CGRectMake(builder.table.cellHeight*0.5, builder.table.cellHeight-0.5, builder.table.cellWidth-builder.table.cellHeight*0.5, 0.5);
            builder.table.bottomLineColor=KCOLOR_LINE;
            
            //标题
            builder.table.hasTitle=YES;
            builder.table.titleFrame=CGRectMake(builder.table.cellHeight*0.5, builder.table.cellHeight*0.05, builder.table.cellWidth*0.6, builder.table.cellHeight*0.45);
            builder.table.titleFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.24];
            builder.table.titleAlignment=NSTextAlignmentLeft;
            builder.table.titleLineBreak=NSLineBreakByTruncatingTail;
            builder.table.titleLines=1;
            builder.table.titleColor=KCOLOR_DARK;
            
            //内容
            builder.table.hasContent=YES;
            builder.table.contentFrame=CGRectMake(builder.table.cellHeight*0.5, builder.table.cellHeight*0.4, builder.table.cellWidth-builder.table.cellHeight*1, builder.table.cellHeight*0.55);
            builder.table.contentFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.contentAlignment=NSTextAlignmentLeft;
            builder.table.contentLineBreak=NSLineBreakByTruncatingTail;
            builder.table.contentLines=2;
            builder.table.contentColor=COLOR(COLOR_G40);
            
            //标签
            builder.table.hasLabel1=YES;
            builder.table.label1Frame=CGRectMake(builder.table.cellWidth-builder.table.cellHeight*0.5-builder.table.cellWidth*0.6, builder.table.cellHeight*0.08, builder.table.cellWidth*0.6, builder.table.cellHeight*0.42);
            builder.table.label1Font=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.label1Alignment=NSTextAlignmentRight;
            builder.table.label1LineBreak=NSLineBreakByTruncatingTail;
            builder.table.label1Lines=1;
            builder.table.label1Color=KCOLOR_CYAN;
            
            //按钮
            builder.table.hasButton1=YES;
            builder.table.buttonLineWidth=1.0f;
            builder.table.button1Frame=CGRectMake(builder.table.cellWidth-builder.table.cellHeight*0.5+builder.table.cellHeight*0.075, builder.table.cellHeight*0.35, builder.table.cellHeight*0.3, builder.table.cellHeight*0.3);
            builder.table.button1Type=KATButtonTypeRight;
            builder.table.button1Color=builder.table.label1Color;
            
            //点击颜色
            builder.table.tapedBgColor=KCOLOR_CYAN;
            builder.table.tapedButtonColor=COLOR(COLOR_SMOKE);
            builder.table.tapedTextColor=COLOR(COLOR_SMOKE);
            
            //点击变色
            builder.table.isTapToChangeFaceLayerColor=YES;
            
            break;
            
            
        case TABLE_STYLE_MESSAGE_RICH://信息类型(富文本)
            
            //高度
            if(cellHeight<1.0)
            {
                builder.table.cellHeight=(builder.screenSize.width-320.0)*0.1+320*0.18;
            }
            else
            {
                builder.table.cellHeight=cellHeight;
            }
            
            //图层颜色
            builder.table.midBgColor=KCOLOR_BACKGROUND;
            
            //分割线
            builder.table.hasLine1=YES;
            builder.table.line1Frame=CGRectMake(-builder.table.cellWidth, builder.table.cellHeight-0.5, builder.table.cellWidth*3, 0.5);
            builder.table.line1Color=KCOLOR_LINE;
            
            //标题
            builder.table.hasRichTitle=YES;
            builder.table.richTitleFrame=CGRectMake(builder.table.cellHeight*0.5, builder.table.cellHeight*0.04, builder.table.cellWidth*0.6, builder.table.cellHeight*0.45);
            builder.table.richTitleStyle=[KATTextStyle textStyle];
            builder.table.richTitleStyle.textFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.24];
            builder.table.richTitleStyle.phoneFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.24];
            builder.table.richTitleStyle.urlFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.24];
            builder.table.richTitleStyle.textAlignment=NSTextAlignmentLeft;
            builder.table.richTitleStyle.lines=1;
            builder.table.richTitleStyle.textColor=KCOLOR_DARK;
            
            //内容
            builder.table.hasRichContent=YES;
            builder.table.richContentFrame=CGRectMake(builder.table.cellHeight*0.5, builder.table.cellHeight*0.35, builder.table.cellWidth-builder.table.cellHeight*1, builder.table.cellHeight*0.62);
            builder.table.richContentStyle=[KATTextStyle textStyle];
            builder.table.richContentStyle.textFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.richContentStyle.phoneFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.richContentStyle.urlFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.richContentStyle.textAlignment=NSTextAlignmentLeft;
            builder.table.richContentStyle.lines=2;
            builder.table.richContentStyle.textColor=COLOR(COLOR_G40);
            
            
            //标签
            builder.table.hasRichLabel=YES;
            builder.table.richLabelFrame=CGRectMake(builder.table.cellWidth-builder.table.cellHeight*0.5-builder.table.cellWidth*0.6, builder.table.cellHeight*0.07, builder.table.cellWidth*0.6, builder.table.cellHeight*0.42);
            builder.table.richLabelStyle=[KATTextStyle textStyle];
            builder.table.richLabelStyle.textFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.richLabelStyle.phoneFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.richLabelStyle.urlFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.richLabelStyle.textAlignment=NSTextAlignmentRight;
            builder.table.richLabelStyle.lines=1;
            builder.table.richLabelStyle.textColor=KCOLOR_CYAN;
            
            
            //按钮
            builder.table.hasButton1=YES;
            builder.table.buttonLineWidth=1.0f;
            builder.table.button1Frame=CGRectMake(builder.table.cellWidth-builder.table.cellHeight*0.5+builder.table.cellHeight*0.075, builder.table.cellHeight*0.35, builder.table.cellHeight*0.3, builder.table.cellHeight*0.3);
            builder.table.button1Type=KATButtonTypeRight;
            builder.table.button1Color=builder.table.richLabelStyle.textColor;
            
            //点击颜色
            builder.table.tapedBgColor=KCOLOR_CYAN;
            builder.table.tapedButtonColor=COLOR(COLOR_SMOKE);
            builder.table.tapedTextColor=COLOR(COLOR_SMOKE);
            
            //点击变色
            builder.table.isTapToChangeFaceLayerColor=YES;
            
            break;
            
            
        case TABLE_STYLE_COLOR_NOTE://彩色账本
            
            //高度
            if(cellHeight<1.0)
            {
                builder.table.cellHeight=(builder.screenSize.width-320.0)*0.1+320*0.18;
            }
            else
            {
                builder.table.cellHeight=cellHeight;
            }
                        
            //图层颜色
            builder.table.midBgColor=KCOLOR_WHITE;
            
            //分割线
            builder.table.hasBottomLine=YES;
            builder.table.bottomLineFrame=CGRectMake(builder.table.cellHeight*0.5, builder.table.cellHeight-0.5, builder.table.cellWidth-builder.table.cellHeight*0.5, 0.5);
            builder.table.bottomLineColor=KCOLOR_LINE;
            
            //标题
            builder.table.hasTitle=YES;
            builder.table.titleFrame=CGRectMake(builder.table.cellHeight*0.5, builder.table.cellHeight*0.05, builder.table.cellWidth*0.6, builder.table.cellHeight*0.55);
            builder.table.titleFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.33];
            builder.table.titleAlignment=NSTextAlignmentLeft;
            builder.table.titleLineBreak=NSLineBreakByTruncatingTail;
            builder.table.titleLines=1;
            builder.table.titleColor=KCOLOR_DARK;
            
            //内容
            builder.table.hasContent=YES;
            builder.table.contentFrame=CGRectMake(builder.table.cellHeight*0.5, builder.table.cellHeight*0.6, builder.table.cellWidth-builder.table.cellHeight*1, builder.table.cellHeight*0.35);
            builder.table.contentFont=[UIFont systemFontOfSize:builder.table.cellHeight*0.22];
            builder.table.contentAlignment=NSTextAlignmentLeft;
            builder.table.contentLineBreak=NSLineBreakByTruncatingTail;
            builder.table.contentLines=1;
            builder.table.contentColor=KCOLOR_GRAY;
            
            //标签
            builder.table.hasLabel1=YES;
            builder.table.label1Frame=CGRectMake(builder.table.cellWidth-builder.table.cellHeight*0.5-builder.table.cellWidth*0.6, builder.table.cellHeight*0.05, builder.table.cellWidth*0.6, builder.table.cellHeight*0.55);
            builder.table.label1Font=[UIFont systemFontOfSize:builder.table.cellHeight*0.2];
            builder.table.label1Alignment=NSTextAlignmentRight;
            builder.table.label1LineBreak=NSLineBreakByTruncatingTail;
            builder.table.label1Lines=1;
            builder.table.label1Color=COLOR(COLOR_G40);
            
            //按钮
            builder.table.hasButton1=YES;
            builder.table.buttonLineWidth=1.0f;
            builder.table.button1Frame=CGRectMake(builder.table.cellWidth-builder.table.cellHeight*0.5+builder.table.cellHeight*0.075, builder.table.cellHeight*0.35, builder.table.cellHeight*0.3, builder.table.cellHeight*0.3);
            builder.table.button1Type=KATButtonTypeRight;
            builder.table.button1Color=builder.table.label1Color;
            
            //点击变色
            builder.table.isTapToChangeFaceLayerColor=YES;
            
            break;
            
    }
    
    
    return builder;
}



//设置删除样式(使用背部图层会有冲突)
- (void)setDeleteModeWithButtonType:(KATButtonType)type
{
    //基本信息
    _deleteEnabled=YES;
    _table.canMoveLeft=YES;
    _table.canPanCell=YES;
    _table.leftMovingDst=_table.cellHeight*1.0;
    
    //配置背景颜色
    _table.backBgColor=KCOLOR_RED;
    
    //配置背部按钮1
    _table.hasBackButton7=YES;
    _table.backButton7Frame=CGRectMake(_table.frame.size.width-_table.cellHeight+_table.cellHeight*0.2, _table.cellHeight*0.2, _table.cellHeight*0.6, _table.cellHeight*0.6);
    _table.backButton7Color=KCOLOR_BACKGROUND;
    _table.backButton7Type=type;
    _table.backButtonLineWidth=1.5f;
    _table.hasBackButton7TapEvent=YES;
    
    
}






- (void)dealloc
{
    NSLog(@"KATTableBuilder is delloc!!");
    
    [super dealloc];
}


@end
